/*不使用任何内建的哈希表库设计一个哈希集合（HashSet）。
* 实现 MyHashSet 类
* void add(key) 向哈希集合中插入值 key
* bool contains(key) 返回哈希集合中是否存在这个值 key 。
* void remove(key) 将给定值 key 从哈希集合中删除。如果哈希集合中没有这个值，什么也不做。
* */

package newcoder.Set_2;

import java.util.Arrays;
import java.util.Map;

public class Leetcode705 {

    public static void main(String[] args) {

        MyHashSet obj = new MyHashSet();
        String[] str = {"MyHashSet", "add", "add", "contains", "contains", "add", "contains",
        "remove", "contains"};
        int[][] nums = {{}, {1}, {2}, {1}, {3}, {2}, {2}, {2}, {2}};
        String[] res = new String[str.length];
        for (int i = 0;i < str.length;i++){

            if (str[i] == "MyHashSet"){
                res[i] = null;
            }
            if (str[i] == "add"){
                obj.add(nums[i][0]);
                res[i] = null;
            }
            if (str[i] == "remove"){
                obj.remove(nums[i][0]);
                res[i] = null;
            }
            if (str[i] == "contains"){
                obj.remove(nums[i][0]);
                res[i] = Boolean.toString(obj.contains(nums[i][0]));
            }
        }
        System.out.println(Arrays.toString(res));
    }
}

class MyHashSet{

    //暂时不会(裂开)，先偷鸡一波
    boolean[] b = new boolean[1000009];
    public MyHashSet(){

    }

    public void add(int key){
        b[key] = true;
    }

    public void remove(int key){
        b[key] = false;
    }

    public boolean contains(int key){
        return b[key];
    }
}
